<template>
  <div class="container">
    <h3>新增课程</h3>
    名称：
    <el-input size="small " type="text" v-model="newCourse.name" /> <br />
    专业：<el-select v-model="newCourse.subjectsId" placeholder="请选择">
      <el-option v-for="item in subjects" :key="item._id" :label="item.name"
        :value="item._id">
      </el-option>
    </el-select>

    <br />
    <el-button type="primary" @click="add">新增课程</el-button>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapActions } = createNamespacedHelpers("subject");
export default {
  data() {
    return {
      newCourse: {
      },
    };
  },
  computed: {
    ...mapState(['subjects'])
  },
  methods: {
    // 增加课程
    add() {
      this.$api.courseApi.addCourses(this.newCourse).then(({ data }) => {
        this.$message.success(data.message);
      });
    },
    // 获取专业
    ...mapActions(['getSubject']),
  },
  created() {
    this.getSubject();
  },
};
</script>

<style scoped>
.img {
  margin-bottom: 10px;
}
.container {
  background-color: #fff;

  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 30px;
}
</style>
